Imports System.Data
Imports System.Xml
Imports System.Data.SqlClient
Imports AppsUtility.EncDec

Public Class frmLedgerReport

    Inherits System.Windows.Forms.Form
    Public OpgBal As Decimal = 0
    Public ClgBal As Decimal = 0
    Dim util As New AppsUtility.EncDec
    Friend WithEvents cmdPrint As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdExit As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdRefresh As DevComponents.DotNetBar.ButtonX
    Friend WithEvents GroupPanel1 As DevComponents.DotNetBar.Controls.GroupPanel
    Friend WithEvents cmbToAcc As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents cmbFromAcc As DevComponents.DotNetBar.Controls.ComboBoxEx
    Public strCon As String = util.toDecrypt(System.Configuration.ConfigurationSettings.AppSettings("SQLString"))

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents SubCode2 As System.Windows.Forms.TextBox
    Friend WithEvents MainCode2 As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents SubCode1 As System.Windows.Forms.TextBox
    Friend WithEvents MainCode1 As System.Windows.Forms.TextBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents dtpToDate As System.Windows.Forms.DateTimePicker
    Friend WithEvents dtpFromDate As System.Windows.Forms.DateTimePicker
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents dgTrxEnq As System.Windows.Forms.DataGrid
    Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
    Friend WithEvents gLlistOfLedgerReport1 As GLlistOfLedgerReport
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.SubCode2 = New System.Windows.Forms.TextBox()
        Me.MainCode2 = New System.Windows.Forms.TextBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.SubCode1 = New System.Windows.Forms.TextBox()
        Me.MainCode1 = New System.Windows.Forms.TextBox()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.dgTrxEnq = New System.Windows.Forms.DataGrid()
        Me.dtpToDate = New System.Windows.Forms.DateTimePicker()
        Me.dtpFromDate = New System.Windows.Forms.DateTimePicker()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.gLlistOfLedgerReport1 = New GLlistOfLedgerReport()
        Me.cmdPrint = New DevComponents.DotNetBar.ButtonX()
        Me.cmdExit = New DevComponents.DotNetBar.ButtonX()
        Me.cmdRefresh = New DevComponents.DotNetBar.ButtonX()
        Me.GroupPanel1 = New DevComponents.DotNetBar.Controls.GroupPanel()
        Me.cmbFromAcc = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.cmbToAcc = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        CType(Me.dgTrxEnq, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.GroupPanel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'SubCode2
        '
        Me.SubCode2.AcceptsReturn = True
        Me.SubCode2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.SubCode2.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.SubCode2.Location = New System.Drawing.Point(178, 86)
        Me.SubCode2.MaxLength = 3
        Me.SubCode2.Name = "SubCode2"
        Me.SubCode2.Size = New System.Drawing.Size(40, 26)
        Me.SubCode2.TabIndex = 203
        '
        'MainCode2
        '
        Me.MainCode2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.MainCode2.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.MainCode2.Location = New System.Drawing.Point(122, 86)
        Me.MainCode2.MaxLength = 4
        Me.MainCode2.Name = "MainCode2"
        Me.MainCode2.Size = New System.Drawing.Size(53, 26)
        Me.MainCode2.TabIndex = 202
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.BackColor = System.Drawing.Color.Transparent
        Me.Label3.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label3.Location = New System.Drawing.Point(17, 62)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(78, 18)
        Me.Label3.TabIndex = 273
        Me.Label3.Text = "To  Account"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'SubCode1
        '
        Me.SubCode1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.SubCode1.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.SubCode1.Location = New System.Drawing.Point(178, 42)
        Me.SubCode1.MaxLength = 3
        Me.SubCode1.Name = "SubCode1"
        Me.SubCode1.Size = New System.Drawing.Size(40, 26)
        Me.SubCode1.TabIndex = 201
        '
        'MainCode1
        '
        Me.MainCode1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.MainCode1.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.MainCode1.Location = New System.Drawing.Point(122, 42)
        Me.MainCode1.MaxLength = 4
        Me.MainCode1.Name = "MainCode1"
        Me.MainCode1.Size = New System.Drawing.Size(53, 26)
        Me.MainCode1.TabIndex = 200
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.BackColor = System.Drawing.Color.Transparent
        Me.Label5.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label5.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label5.Location = New System.Drawing.Point(17, 18)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(96, 18)
        Me.Label5.TabIndex = 267
        Me.Label5.Text = "From  Account"
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'dgTrxEnq
        '
        Me.dgTrxEnq.AllowSorting = False
        Me.dgTrxEnq.BackgroundColor = System.Drawing.Color.AliceBlue
        Me.dgTrxEnq.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.dgTrxEnq.CaptionVisible = False
        Me.dgTrxEnq.DataMember = ""
        Me.dgTrxEnq.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dgTrxEnq.Location = New System.Drawing.Point(18, 127)
        Me.dgTrxEnq.Name = "dgTrxEnq"
        Me.dgTrxEnq.PreferredColumnWidth = 175
        Me.dgTrxEnq.ReadOnly = True
        Me.dgTrxEnq.Size = New System.Drawing.Size(822, 301)
        Me.dgTrxEnq.TabIndex = 274
        Me.dgTrxEnq.TabStop = False
        '
        'dtpToDate
        '
        Me.dtpToDate.Format = System.Windows.Forms.DateTimePickerFormat.[Short]
        Me.dtpToDate.Location = New System.Drawing.Point(617, 86)
        Me.dtpToDate.Name = "dtpToDate"
        Me.dtpToDate.Size = New System.Drawing.Size(111, 26)
        Me.dtpToDate.TabIndex = 278
        '
        'dtpFromDate
        '
        Me.dtpFromDate.Format = System.Windows.Forms.DateTimePickerFormat.[Short]
        Me.dtpFromDate.Location = New System.Drawing.Point(617, 42)
        Me.dtpFromDate.Name = "dtpFromDate"
        Me.dtpFromDate.Size = New System.Drawing.Size(114, 26)
        Me.dtpFromDate.TabIndex = 277
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.BackColor = System.Drawing.Color.Transparent
        Me.Label2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label2.Location = New System.Drawing.Point(539, 62)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(54, 18)
        Me.Label2.TabIndex = 276
        Me.Label2.Text = "To Date"
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label1.Location = New System.Drawing.Point(539, 18)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(72, 18)
        Me.Label1.TabIndex = 275
        Me.Label1.Text = "From Date"
        '
        'cmdPrint
        '
        Me.cmdPrint.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdPrint.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdPrint.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdPrint.Location = New System.Drawing.Point(670, 445)
        Me.cmdPrint.Name = "cmdPrint"
        Me.cmdPrint.Size = New System.Drawing.Size(82, 27)
        Me.cmdPrint.TabIndex = 282
        Me.cmdPrint.Text = "Print"
        '
        'cmdExit
        '
        Me.cmdExit.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdExit.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdExit.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdExit.Location = New System.Drawing.Point(758, 445)
        Me.cmdExit.Name = "cmdExit"
        Me.cmdExit.Size = New System.Drawing.Size(82, 27)
        Me.cmdExit.TabIndex = 281
        Me.cmdExit.Text = "Exit"
        '
        'cmdRefresh
        '
        Me.cmdRefresh.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdRefresh.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdRefresh.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdRefresh.Location = New System.Drawing.Point(582, 445)
        Me.cmdRefresh.Name = "cmdRefresh"
        Me.cmdRefresh.Size = New System.Drawing.Size(82, 27)
        Me.cmdRefresh.TabIndex = 282
        Me.cmdRefresh.Text = "Refresh"
        '
        'GroupPanel1
        '
        Me.GroupPanel1.CanvasColor = System.Drawing.SystemColors.Control
        Me.GroupPanel1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007
        Me.GroupPanel1.Controls.Add(Me.cmbFromAcc)
        Me.GroupPanel1.Controls.Add(Me.cmbToAcc)
        Me.GroupPanel1.Controls.Add(Me.Label2)
        Me.GroupPanel1.Controls.Add(Me.Label3)
        Me.GroupPanel1.Controls.Add(Me.Label5)
        Me.GroupPanel1.Controls.Add(Me.Label1)
        Me.GroupPanel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GroupPanel1.Location = New System.Drawing.Point(0, 0)
        Me.GroupPanel1.Name = "GroupPanel1"
        Me.GroupPanel1.Size = New System.Drawing.Size(858, 503)
        '
        '
        '
        Me.GroupPanel1.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2
        Me.GroupPanel1.Style.BackColorGradientAngle = 90
        Me.GroupPanel1.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground
        Me.GroupPanel1.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderBottomWidth = 1
        Me.GroupPanel1.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder
        Me.GroupPanel1.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderLeftWidth = 1
        Me.GroupPanel1.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderRightWidth = 1
        Me.GroupPanel1.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderTopWidth = 1
        Me.GroupPanel1.Style.CornerDiameter = 4
        Me.GroupPanel1.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded
        Me.GroupPanel1.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center
        Me.GroupPanel1.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText
        Me.GroupPanel1.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near
        Me.GroupPanel1.TabIndex = 283
        Me.GroupPanel1.Text = "GL Ledger Report"
        '
        'cmbFromAcc
        '
        Me.cmbFromAcc.DisplayMember = "Text"
        Me.cmbFromAcc.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbFromAcc.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbFromAcc.ItemHeight = 19
        Me.cmbFromAcc.Location = New System.Drawing.Point(221, 19)
        Me.cmbFromAcc.Name = "cmbFromAcc"
        Me.cmbFromAcc.Size = New System.Drawing.Size(277, 25)
        Me.cmbFromAcc.TabIndex = 277
        '
        'cmbToAcc
        '
        Me.cmbToAcc.DisplayMember = "Text"
        Me.cmbToAcc.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbToAcc.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbToAcc.ItemHeight = 19
        Me.cmbToAcc.Location = New System.Drawing.Point(221, 62)
        Me.cmbToAcc.Name = "cmbToAcc"
        Me.cmbToAcc.Size = New System.Drawing.Size(277, 25)
        Me.cmbToAcc.TabIndex = 277
        '
        'frmLedgerReport
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(7, 19)
        Me.BackColor = System.Drawing.SystemColors.ActiveCaption
        Me.ClientSize = New System.Drawing.Size(858, 503)
        Me.ControlBox = False
        Me.Controls.Add(Me.cmdRefresh)
        Me.Controls.Add(Me.cmdPrint)
        Me.Controls.Add(Me.cmdExit)
        Me.Controls.Add(Me.dtpToDate)
        Me.Controls.Add(Me.dtpFromDate)
        Me.Controls.Add(Me.dgTrxEnq)
        Me.Controls.Add(Me.MainCode1)
        Me.Controls.Add(Me.SubCode2)
        Me.Controls.Add(Me.MainCode2)
        Me.Controls.Add(Me.SubCode1)
        Me.Controls.Add(Me.GroupPanel1)
        Me.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Location = New System.Drawing.Point(20, 50)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmLedgerReport"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        CType(Me.dgTrxEnq, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupPanel1.ResumeLayout(False)
        Me.GroupPanel1.PerformLayout()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Sub Budgets_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ds2, ds3 As DataSet
        Dim GLdata As New GLdataLogic
        ds2 = GLdata.GetAccountsByCompany(CompanyID, 0, 0)
        cmbFromAcc.DataSource = ds2.Tables(0)
        cmbFromAcc.ValueMember = "AccountID"
        cmbFromAcc.DisplayMember = "AccountName"
        '
        ds3 = GLdata.GetAccountsByCompany(CompanyID, 0, 0)
        cmbToAcc.DataSource = ds3.Tables(0)
        cmbToAcc.ValueMember = "AccountID"
        cmbToAcc.DisplayMember = "AccountName"
        GLdata = Nothing
    End Sub

    Private Sub cmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click
        Me.Cursor = Cursors.WaitCursor
        dgTrxEnq_load()
        Me.Cursor = Cursors.Default
    End Sub
    Private Sub cmbChart1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbFromAcc.KeyUp
        AutoCompleteCombo_KeyUp(cmbFromAcc, e)
        If e.KeyCode = Keys.Enter Then
            SendKeys.Send("{Tab}")
        End If
    End Sub
    Private Sub cmbChart1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbFromAcc.Leave
        AutoCompleteCombo_Leave(cmbFromAcc)
    End Sub
    Private Sub cmbChart1_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbFromAcc.Validated
        If IsNumeric(cmbFromAcc.SelectedValue) Then
            Dim AcID As Integer
            AcID = cmbFromAcc.SelectedValue
            Dim GLdata As New GLdataLogic
            Dim ds3 As DataSet
            ds3 = GLdata.GetAccountDetailsByAccountID(AcID)
            MainCode1.Text = ds3.Tables(0).Rows(0).Item("AccountNumber")
            SubCode1.Text = ds3.Tables(0).Rows(0).Item("AccountCenter")
            GLdata = Nothing
        End If
    End Sub

    Private Sub cmbChart1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbFromAcc.Click
        If IsNumeric(cmbFromAcc.SelectedValue) Then
            Dim AcID As Integer
            AcID = cmbFromAcc.SelectedValue
            Dim GLdata As New GLdataLogic
            Dim ds3 As DataSet
            ds3 = GLdata.GetAccountDetailsByAccountID(AcID)
            MainCode1.Text = ds3.Tables(0).Rows(0).Item("AccountNumber")
            MainCode2.Text = ds3.Tables(0).Rows(0).Item("AccountCenter")
            GLdata = Nothing
        End If
    End Sub

    Private Sub MainCode1_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MainCode1.Validated
        If MainCode1.Text.Trim() <> "" And SubCode1.Text.Trim <> "" Then
            If ValidateAccountCode1() = False Then
                MsgBox("Invalid Account", MsgBoxStyle.Critical, "Inventory Manager")
                MainCode1.Text = ""
                SubCode1.Text = ""
                MainCode1.Focus()
            End If
        End If
    End Sub
    Private Function ValidateAccountCode1() As Boolean
        Dim GLdata As New GLdataLogic
        Try
            Dim ds As DataSet
            ds = GLdata.GetAccountDetails(CompanyID, MainCode1.Text, SubCode1.Text)
            If ds.Tables(0).Rows.Count() = 0 Then
                GLdata = Nothing
                Return False
            End If
            cmbFromAcc.SelectedValue = ds.Tables(0).Rows(0).Item("AccountID")
            Return True
        Catch ex As Exception
            GLdata = Nothing
            'MsgBox("Unable to satisfy your request." & vbLf & "Try again later.", MsgBoxStyle.Critical, "Inventory Manager")
            Return False
        End Try
    End Function
    Private Sub MainCode1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MainCode1.KeyUp
        If e.KeyCode = Keys.Enter Then
            If MainCode1.Text <> "" Then
                SendKeys.Send("{Tab}")
            Else
                SubCode1.Focus()
            End If
        End If
    End Sub

    Private Sub SubCode1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles SubCode1.KeyUp
        If e.KeyCode = Keys.Enter Then
            If MainCode1.Text = "" Then
                SubCode1.Text = "000"
            End If
            SendKeys.Send("{Tab}")
        End If
    End Sub
    Private Sub SubCode1_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubCode1.Validated
        If SubCode1.Text.Trim = "" Then
            SubCode1.Text = "000"
        End If
        If MainCode1.Text.Trim() <> "" And SubCode1.Text.Trim <> "" Then
            If ValidateAccountCode1() = False Then
                MsgBox("Invalid Account", MsgBoxStyle.Critical, "Inventory Manager")
                MainCode1.Text = ""
                SubCode1.Text = ""
                MainCode1.Focus()
            End If
        End If
    End Sub

    Private Sub cmbChart2_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbToAcc.KeyUp
        AutoCompleteCombo_KeyUp(cmbToAcc, e)
        If e.KeyCode = Keys.Enter Then
            SendKeys.Send("{Tab}")
        End If
    End Sub
    Private Sub cmbChart2_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbToAcc.Leave
        AutoCompleteCombo_Leave(cmbToAcc)
    End Sub
    Private Sub cmbChart2_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbToAcc.Validated
        If IsNumeric(cmbToAcc.SelectedValue) Then
            Dim AcID As Integer
            AcID = cmbToAcc.SelectedValue
            Dim GLdata As New GLdataLogic
            Dim ds3 As DataSet
            ds3 = GLdata.GetAccountDetailsByAccountID(AcID)
            MainCode2.Text = ds3.Tables(0).Rows(0).Item("AccountNumber")
            SubCode2.Text = ds3.Tables(0).Rows(0).Item("AccountCenter")
            GLdata = Nothing
        End If
    End Sub

    Private Sub cmbChart2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbToAcc.Click
        If IsNumeric(cmbToAcc.SelectedValue) Then
            Dim AcID As Integer
            AcID = cmbToAcc.SelectedValue
            Dim GLdata As New GLdataLogic
            Dim ds3 As DataSet
            ds3 = GLdata.GetAccountDetailsByAccountID(AcID)
            MainCode2.Text = ds3.Tables(0).Rows(0).Item("AccountNumber")
            MainCode2.Text = ds3.Tables(0).Rows(0).Item("AccountCenter")
            GLdata = Nothing
        End If
    End Sub

    Private Sub dgTrxEnq_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgTrxEnq.MouseUp
        Dim pt As New Point(e.X, e.Y)
        Dim hti As DataGrid.HitTestInfo = dgTrxEnq.HitTest(pt)
        If hti.Type = DataGrid.HitTestType.Cell Then
            dgTrxEnq.CurrentCell = New DataGridCell(hti.Row, hti.Column)
            dgTrxEnq.Select(hti.Row)
        End If
    End Sub
    Private Sub MainCode2_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MainCode2.Validated
        If MainCode2.Text.Trim() <> "" And SubCode2.Text.Trim <> "" Then
            If ValidateAccountCode2() = False Then
                MsgBox("Invalid Account", MsgBoxStyle.Critical, "Inventory Manager")
                MainCode2.Text = ""
                SubCode2.Text = ""
                MainCode2.Focus()
            End If
        End If
    End Sub
    Private Function ValidateAccountCode2() As Boolean
        Dim GLdata As New GLdataLogic
        Try
            Dim ds As DataSet
            ds = GLdata.GetAccountDetails(CompanyID, MainCode2.Text, SubCode2.Text)
            If ds.Tables(0).Rows.Count() = 0 Then
                GLdata = Nothing
                Return False
            End If
            cmbToAcc.SelectedValue = ds.Tables(0).Rows(0).Item("AccountID")
            Return True
        Catch ex As Exception
            GLdata = Nothing
            'MsgBox("Unable to satisfy your request." & vbLf & "Try again later.", MsgBoxStyle.Critical, "Inventory Manager")
            Return False
        End Try
    End Function
    Private Sub MainCode2_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MainCode2.KeyUp
        If e.KeyCode = Keys.Enter Then
            If MainCode2.Text <> "" Then
                SendKeys.Send("{Tab}")
            Else
                SubCode2.Focus()
            End If
        End If
    End Sub

    Private Sub SubCode2_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles SubCode2.KeyUp
        If e.KeyCode = Keys.Enter Then
            If MainCode2.Text = "" Then
                SubCode2.Text = "000"
            End If
            SendKeys.Send("{Tab}")
        End If
    End Sub
    Private Sub SubCode2_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubCode2.Validated
        If SubCode2.Text.Trim = "" Then
            SubCode2.Text = "000"
        End If
        If MainCode2.Text.Trim() <> "" And SubCode2.Text.Trim <> "" Then
            If ValidateAccountCode2() = False Then
                MsgBox("Invalid Account", MsgBoxStyle.Critical, "Inventory Manager")
                MainCode2.Text = ""
                SubCode2.Text = ""
                MainCode2.Focus()
            End If
        End If
    End Sub

    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        Me.Hide()
    End Sub
    Private Sub dgTrxEnq_Style()
        With dgTrxEnq
            .TableStyles.Clear()
            .CaptionBackColor = System.Drawing.Color.SlateBlue
            .CaptionForeColor = System.Drawing.Color.LemonChiffon
            .AllowSorting = False
            .AlternatingBackColor = System.Drawing.Color.AliceBlue
            .ParentRowsBackColor = System.Drawing.Color.Lavender
            .ParentRowsForeColor = System.Drawing.Color.SlateBlue
            .HeaderBackColor = System.Drawing.Color.LemonChiffon
            .AllowNavigation = False
            .ParentRowsVisible = False
            .RowHeadersVisible = False
        End With

        Dim grdTableStyle As New DataGridTableStyle
        With grdTableStyle
            .AlternatingBackColor = Color.AliceBlue
            .HeaderFont = New Font("Calibri", 9.0!, FontStyle.Bold)
            .MappingName = "TRENQ"
            .PreferredColumnWidth = 160
            .HeaderBackColor = Color.LightSlateGray
            .HeaderForeColor = Color.LightCyan
            .PreferredRowHeight = 15
            .RowHeadersVisible = False
            .RowHeaderWidth = 0
        End With

        Dim cs As DataGridColumnStyle
        cs = New DataGridTextBoxColumn
        cs.Width = 100
        cs.MappingName = "TrxDate"
        cs.HeaderText = "Date"
        cs.NullText = ""
        grdTableStyle.GridColumnStyles.Add(cs)

        Dim cs1 As DataGridColumnStyle
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 130
        cs1.MappingName = "TrxSource"
        cs1.HeaderText = "Refer#"
        cs1.NullText = ""
        grdTableStyle.GridColumnStyles.Add(cs1)

        Dim cs2 As DataGridColumnStyle
        cs2 = New DataGridTextBoxColumn  ' Add the standard column style.
        cs2.Width = 270
        cs2.MappingName = "TrxRefer"
        cs2.HeaderText = "Description"
        cs2.NullText = ""
        cs2.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs2)

        Dim cs3 As DataGridColumnStyle
        cs3 = New DataGridTextBoxColumn
        cs3.Width = 100
        cs3.MappingName = "TrxNumber"
        cs3.HeaderText = "Trx.No."
        cs3.NullText = ""
        grdTableStyle.GridColumnStyles.Add(cs3)

        Dim cs0 As DataGridColumnStyle
        cs0 = New DataGridTextBoxColumn  ' Add the standard column style.
        cs0.Width = 105
        cs0.MappingName = "DrAmount"
        cs0.HeaderText = "Debit Amount "
        cs0.NullText = ""
        cs0.ReadOnly = True
        cs0.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs0)

        Dim cs4 As DataGridColumnStyle
        cs4 = New DataGridTextBoxColumn  ' Add the standard column style.
        cs4.Width = 105
        cs4.MappingName = "CrAmount"
        cs4.HeaderText = "Credit Amount "
        cs4.NullText = ""
        cs4.ReadOnly = True
        cs4.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs4)

        dgTrxEnq.TableStyles.Add(grdTableStyle)

    End Sub
    Private Sub dgTrxEnq_load()
        Try
            Dim FrDt, ToDt As String
            FrDt = dtpFromDate.Text
            ToDt = dtpToDate.Text
            FrDt = FrDt.Substring(6, 4) & "-" & FrDt.Substring(3, 2) & "-" & FrDt.Substring(0, 2)
            ToDt = ToDt.Substring(6, 4) & "-" & ToDt.Substring(3, 2) & "-" & ToDt.Substring(0, 2)
            Dim strsql As String
            Dim sqlCon As SqlConnection = New SqlConnection(strCon)
            sqlCon.Open()

            'If SubCode1.Text = "000" And SubCode2.Text = "000" Then
            '    subcodeGL = " "
            'Else
            '    subcodeGL = " and ACCENT = '" & SubCode1.Text & "' "
            'End If

            strsql = "Exec GlReport " & CompanyID & "," & MainCode1.Text & "," & MainCode2.Text & ",'" & FrDt & "','" & ToDt & "','" & SubCode1.Text & "'"
            Dim da As New SqlClient.SqlDataAdapter(strsql, sqlCon)
            Dim ds As New DataSet("TRENQ")
            da.Fill(ds, "TRENQ")
            Dim drow As DataRow
            For Each drow In ds.Tables(0).Rows
                If drow("SeqNo") = "1" Then
                    drow("TrxDate") = System.DBNull.Value
                End If
                If drow("SeqNo") = "2" Then
                    If Not IsDBNull(drow("CrAmount")) Then
                        drow("CrAmount") = 0 - drow("CrAmount")
                        drow("CrAmount") = CDbl(drow("CrAmount")).ToString("#,##0.000")
                        drow("DrAmount") = System.DBNull.Value
                    End If
                End If
                If drow("SeqNo") = "3" Then
                    If Not IsDBNull(drow("CrAmount")) Then
                        drow("CrAmount") = CDbl(drow("CrAmount")).ToString("#,##0.000")
                    Else
                        drow("DrAmount") = CDbl(drow("DrAmount")).ToString("#,##0.000")
                    End If
                End If
                If drow("SeqNo") = "4" Then
                    If Not IsDBNull(drow("CrAmount")) Then
                        drow("CrAmount") = 0 - drow("CrAmount")
                        drow("CrAmount") = CDbl(drow("CrAmount")).ToString("#,##0.000")
                        drow("DrAmount") = System.DBNull.Value
                    End If
                End If
            Next
            dgTrxEnq.DataSource = ds
            dgTrxEnq.DataMember = "TRENQ"
            dgTrxEnq.ReadOnly = True
            dgTrxEnq.TableStyles.Clear()
            dgTrxEnq_Style()

            sqlCon.Close()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

        'Here creating a history for report log

    End Sub

    Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrint.Click
        Me.Cursor = Cursors.WaitCursor
        Try
            Dim ds As DataSet = New DataSet("JisRpt")
            Dim table As DataTable = New DataTable("JisRpt")
            table.Columns.Add("Str1")
            table.Columns.Add("Str2")
            table.Columns.Add("Str3")
            table.Columns.Add("Str4")
            table.Columns.Add("Dec1")
            table.Columns.Add("Dec2")

            Dim mrow, drow As Integer
            Dim cm As CurrencyManager = BindingContext(dgTrxEnq.DataSource, dgTrxEnq.DataMember)
            Dim dv As DataView = cm.List
            dv.RowStateFilter = DataViewRowState.CurrentRows
            mrow = dv.Count
            Dim n As Integer
            For n = 0 To mrow - 1
                Dim nrow As DataRow = table.NewRow()
                If nrow("Str1").ToString() <> "" Then
                    nrow("Str1") = Format(CDate(dgTrxEnq.Item(n, 0)), "dd/MM/yyyy")
                Else
                    nrow("Str1") = dgTrxEnq(n, 0)
                End If
                nrow("Str2") = dgTrxEnq(n, 1)
                nrow("Str3") = dgTrxEnq(n, 2)
                nrow("Str4") = dgTrxEnq(n, 3)
                nrow("Dec1") = dgTrxEnq(n, 4)
                nrow("Dec2") = dgTrxEnq(n, 5)
                table.Rows.Add(nrow)
            Next

            ds.Tables.Add(table)
            gLlistOfLedgerReport1.Load()
            gLlistOfLedgerReport1.SetDataSource(ds)

            gLlistOfLedgerReport1.SetParameterValue("CompanyName", " SAFARI HOUSE GENERAL TRADING COMPANY W.L.L ")
            gLlistOfLedgerReport1.SetParameterValue("username", UserName)
            gLlistOfLedgerReport1.SetParameterValue("ReportName", "GENERAL LEDGER REPORT")
            gLlistOfLedgerReport1.SetParameterValue("ReportCriteria", "FOR THE PERIOD FROM " + dtpFromDate.Text + " TO " + dtpToDate.Text)

            If PrntPrv Is Nothing Then
                PrntPrv = New PrintPreviewForm
                PrntPrv.CrRptView.ReportSource = gLlistOfLedgerReport1
                PrntPrv.ShowDialog()
            End If

            'gLlistOfLedgerReport1.PrintToPrinter(1, True, 0, 0)
            gLlistOfLedgerReport1.Close()

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        Me.Cursor = Cursors.Default
    End Sub

End Class
